Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inline-diff): support hide accpet widget #4066

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

bytemain
Copy link
Member

@bytemain bytemain commented Oct 9, 2024

Types

  • 🎉 New Features

Background or solution

支持隐藏 inline diff 的采纳按钮,适用于仅展示 diff 的时候

Changelog

Summary by CodeRabbit

  • 新功能

    • 恢复了 ctrl+yctrl+n 快捷键用于 AI_INLINE_DIFF_PARTIAL_EDIT 命令。
    • 更新了差异预览器的选项配置,增强了灵活性。
  • 改进

    • 增加了新的接口和选项,允许更好地管理和配置预览器的行为。
    • 更新了多个类以支持新的预览选项和状态一致性。

@opensumi opensumi bot added the 🎨 feature feature required label Oct 9, 2024
Ricbet
Ricbet previously approved these changes Oct 9, 2024
Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Walkthrough

此拉取请求对多个类和接口进行了修改,主要集中在增强和恢复与 AI_INLINE_DIFF_PARTIAL_EDIT 命令相关的键绑定功能。具体来说,AINativeBrowserContribution 类恢复了 ctrl+yctrl+n 的键绑定。其他类如 InlineDiffControllerInlineStreamDiffHandlerAcceptPartialEditWidget 也进行了相应的更新,以支持新的选项和接口,增强了差异预览功能。

Changes

文件路径 更改摘要
packages/ai-native/src/browser/ai-core.contribution.ts 恢复 AI_INLINE_DIFF_PARTIAL_EDIT 命令的键绑定,添加 ctrl+yctrl+n 的快捷键。
packages/ai-native/src/browser/widget/inline-diff/inline-diff.controller.ts 更新 createDiffPreviewer 方法,增加 options 参数以支持 LiveInlineDiffPreviewer 的初始化。
packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts 更新 IDiffPreviewerOptions 接口,新增可选属性 hideAcceptPartialEditWidget
packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx 新增 setPreviewerOptions 方法,更新 initializerestoreSnapshot 方法以增强状态一致性。
packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx 新增接口 IPartialEditWidgetOptions,更新 AcceptPartialEditWidget 构造函数以接受新选项参数。
packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx 新增接口 IModelOptions,更新 LivePreviewDiffDecorationModel 类以支持新的选项属性和方法。

Possibly related PRs

Suggested labels

🎨 feature, 💄 style change

Suggested reviewers

  • Ricbet

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
packages/ai-native/src/browser/widget/inline-diff/inline-diff.controller.ts (1)

219-224: 代码变更看起来不错,建议小幅改进以提高可读性。

这个变更通过在实例化 LiveInlineDiffPreviewer 时传递 previewerOptions,增强了预览器的灵活性。这与PR的目标(支持隐藏接受部件的功能)相符。

为了进一步提高代码的可读性和可维护性,建议考虑以下小改进:

 this.previewer = this.injector.get(LiveInlineDiffPreviewer, [
   monacoEditor,
-  {
-    previewerOptions: options,
-  },
+  { previewerOptions: options },
 ]);

这样可以使代码更加简洁,同时保持其功能不变。

packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (2)

22-25: 新属性增加了灵活性,建议稍微调整注释。

新增的 hideAcceptPartialEditWidget 属性很好地增强了差异预览器的灵活性。这允许在只需要展示差异而不需要接受部分编辑的场景中隐藏相关小部件。

建议稍微调整注释,使其更加清晰:

 /**
- * 是否隐藏接受部分编辑的 widget,用于只展示 diff 的场景
+ * 是否隐藏接受部分编辑的 widget
+ * @description 用于只需要展示差异而不需要接受编辑的场景
  */

这样的注释结构更符合 JSDoc 的标准,并且更清晰地分离了属性的作用和使用场景。


Line range hint 321-332: attachNode 方法的改进很好,建议增加错误处理。

attachNode 方法的修改很好地改进了节点重新附加的处理,通过恢复装饰快照来保持状态。新增的 createNodeSnapshot 方法也为节点重建时保留状态提供了有用的机制。

对于 attachNode 方法,建议增加一些错误处理:

 attachNode(node: InlineStreamDiffHandler): void {
   this.node?.dispose();
   this.node = node;

   if (node) {
     const snapshot = node.currentSnapshotStore;
     if (snapshot) {
-      this.node.restoreDecorationSnapshot(snapshot.decorationSnapshotData);
+      try {
+        this.node.restoreDecorationSnapshot(snapshot.decorationSnapshotData);
+      } catch (error) {
+        console.error('恢复装饰快照时发生错误:', error);
+        // 可以在这里添加适当的错误处理逻辑
+      }
       this.listenNode(node);
     }
   }
 }

这样可以捕获并记录恢复过程中可能发生的任何错误,提高代码的健壮性。

packages/ai-native/src/browser/ai-core.contribution.ts (1)

527-541: 新增的快捷键绑定看起来不错!

这些新增的快捷键绑定很好地实现了内联差异部分编辑的功能。以下是一些观察和建议:

  1. 使用 ctrl+y 接受编辑,ctrl+n 拒绝编辑的设计很直观。
  2. 优先级设置为100确保了这些快捷键在特定上下文中的优先使用。
  3. 使用 InlineDiffPartialEditsIsVisible 上下文键可以确保这些快捷键只在相关视图可见时才激活。

为了提高代码的可读性和可维护性,建议添加简短的注释来解释这些快捷键的具体功能。例如:

 keybindings.registerKeybinding({
   command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
   keybinding: 'ctrl+y',
   args: true,
   priority: 100,
   when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
+  // 接受部分编辑
 });
 keybindings.registerKeybinding({
   command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
   keybinding: 'ctrl+n',
   args: false,
   priority: 100,
   when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
+  // 拒绝部分编辑
 });
packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx (1)

127-130: 修正注释的语法错误

注释中应将 "In some case" 改为 "In some cases" 以确保语法正确。

建议应用以下修改:

-   * In some case, we don't want to show the accept and reject button
+   * In some cases, we don't want to show the accept and reject buttons
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0b2824e and 3794cc9.

📒 Files selected for processing (6)
  • packages/ai-native/src/browser/ai-core.contribution.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff.controller.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx (1 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx (3 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx (5 hunks)
🧰 Additional context used
🔇 Additional comments (7)
packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (1)

Line range hint 1-538: 总体评价:代码质量良好,改动合理。

本次更改很好地增强了内联差异预览器的功能和灵活性。新增的 hideAcceptPartialEditWidget 选项为用户提供了更多控制,而 LiveInlineDiffPreviewer 类的改动改进了节点重新附加和快照创建的处理。

代码结构清晰,遵循了良好的编程实践。建议的小改进主要集中在文档完善和错误处理上,这些改进可以进一步提高代码的可维护性和健壮性。

总的来说,这些更改是有价值的,并且与PR的目标(支持隐藏接受小部件)保持一致。

packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx (4)

57-59: 新接口 IModelOptions 添加得当

这个新接口的添加是一个很好的做法。它为部分编辑小部件的配置选项提供了类型安全和清晰的结构。这将有助于提高代码的可维护性和可读性。


84-86: options 属性的添加增强了灵活性

新增的 options 属性为 LivePreviewDiffDecorationModel 类提供了更大的灵活性。通过初始化 partialEditWidgetOptions 为空对象,您为未来可能的扩展提供了一个安全的默认值。这是一个很好的做法,可以在不破坏现有功能的情况下轻松添加新的配置选项。


587-590: createPartialEditWidget 方法的改进增强了灵活性和类型安全

createPartialEditWidget 方法的修改是很好的改进:

  1. 添加了返回类型,提高了类型安全性和代码可读性。
  2. 在创建 AcceptPartialEditWidget 时传入 this.options.partialEditWidgetOptions,增加了配置的灵活性。

这些变更与新添加的 IModelOptions 接口保持一致,使得部分编辑小部件的创建更加可配置和灵活。


718-720: setPreviewerOptions 方法提供了运行时配置的能力

新增的 setPreviewerOptions 方法是一个很好的补充:

  1. 它允许在模型实例化后动态更新选项,增加了灵活性。
  2. 提供运行时更新配置选项的能力是一个良好的实践。
  3. 方法简单直接,符合其预期用途。

这个添加使得 LivePreviewDiffDecorationModel 类更加灵活和可配置,有助于提高代码的可维护性和可扩展性。

packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx (2)

180-183: 条件渲染逻辑正确

renderView 方法中添加了针对 hideAcceptPartialEditWidget 选项的条件判断,确保在需要时不渲染组件,逻辑实现正确。


152-155: 新增构造函数参数,确保兼容性

构造函数增加了可选参数 editWidgetOptions,请确保所有实例化 AcceptPartialEditWidget 的代码已适配新的参数。

运行以下脚本以验证所有 AcceptPartialEditWidget 的实例化是否已更新:

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.41%. Comparing base (0b2824e) to head (10a99d5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4066   +/-   ##
=======================================
  Coverage   54.41%   54.41%           
=======================================
  Files        1590     1590           
  Lines       97268    97268           
  Branches    19906    19906           
=======================================
  Hits        52924    52924           
  Misses      36830    36830           
  Partials     7514     7514           
Flag Coverage Δ
jsdom 49.95% <ø> (ø)
node 15.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bytemain bytemain merged commit 873d8bc into main Oct 9, 2024
11 checks passed
@bytemain bytemain deleted the feat/inline-diff/hide-accept-view branch October 9, 2024 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants